Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[fix] 좋아요 동시성 이슈 해결 #224

Open
wants to merge 16 commits into
base: develop
Choose a base branch
from
Open

[fix] 좋아요 동시성 이슈 해결 #224

wants to merge 16 commits into from

Conversation

kgy1008
Copy link
Member

@kgy1008 kgy1008 commented Dec 2, 2024

Related Issue 📌

close #223

Description ✔️

  • 낙관적 락을 이용해 해결
  • Spring Retry 프레임워크를 활용하여 재시도 로직을 구현하였습니다.

To Reviewers

테스트코드를 짤 줄 몰라서 curl 명령어로 직접 api 테스트 했습니다.
image

후에 운영 서버로 병합되었을 때, 기존의 식당 정보 중 version 컬럼 값이 null인 것들을 0으로 초기화 하는 작업 필요

UPDATE store
SET version = 0
where version is null;

@kgy1008 kgy1008 self-assigned this Dec 2, 2024
import org.hankki.hankkiserver.common.code.ErrorCode;

@Getter
public class ConcurrencyException extends RuntimeException {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

초반에 exception 유형 에러유형400 401... 등으로 하기로 했었음
굳이 이거 새로 만들 필요 있나 싶어요

@EnableRetry
@Configuration
public class RetryConfig {
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

빈 등록하면서 aop 적용순서(transactional이랑 retry) 정해야 하는 거 같기도 하던데 고려된건가요?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

명시적으로 지정해주지 않아도 기본적으로 Spring AOP의 우선순위에 따라 @retryable이 먼저 적용된다고 합니다.

public HeartCreateResponse createHeart(final HeartPostCommand heartPostCommand) {
User user = userFinder.getUserReference(heartPostCommand.userId());
Store store = storeFinder.findByIdWhereDeletedIsFalse(heartPostCommand.storeId());
@Retryable(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

optimisticlockexception 발생하면 retry시키는건가요?

Copy link
Member Author

@kgy1008 kgy1008 Dec 9, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

넹 맞습니다. 다만, noRetryFor을 통해서 재시도 하지 않을 예외들은 제외하였습니다.

@@ -87,4 +108,10 @@ public String getImageUrlOrElseNull() {
public void updateLowestPrice(int lowestPrice) {
this.lowestPrice = lowestPrice;
}

private void validateHeartCount() {
Copy link
Contributor

@PicturePark1101 PicturePark1101 Dec 9, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

BadRequestException이 domain 패키지에 존재하는 클래스에 있는건 적절하지 않은 것 같습니당 차라리 리턴값 boolean 등으로 변경하고 에러는 service 쪽에서 던져주는게 어떨까요?

package org.hankki.hankkiserver.api.store.service.command;

public record HeartCommand(
Long userId,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

이 필드이 필수 값들이라면 원시타입으로 하면 어떨까요?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[fix] 좋아요 수 동시성 이슈 처리
3 participants